const App = {
    data() {
        return {
            tableData: [],
            form: {
                TableName: 'base_word_log',
                Condition: " Start_Datetime BETWEEN '" + getYMDDate() + " 00:00:00' AND '" + getYMDDate() + " 23:59:59'",
                Page: 1, //页码
                Limit: 50
            },
            value: [getYMDDate(), getYMDDate()],
            Total: 0,
            loading: false,
            loading1: false
        }
    },
    mounted() {
        this.postgetList(this.form);
    },
    methods: {
        check(value) {
            try {
                this.form.Condition = " Start_Datetime BETWEEN '" + value[0] + " 00:00:00' AND '" + value[1] + " 23:59:59'";
            } catch (error) {
                this.form.Condition = " Start_Datetime BETWEEN '" + getYMDDate() + " 00:00:00' AND '" + getYMDDate() + " 23:59:59'";
            }
            this.postgetList(this.form)
        },
        reset() {
            window.location.reload();
        },
        handleSizeChange(newSize) {
            this.form.Page = 1;
            this.form.Limit = newSize;
            this.postgetList(this.form);
        },
        handleCurrentChange(newPage) {
            this.form.Page = newPage;
            this.postgetList(this.form);
        },
        postgetList(data) {
            this.loading = true;
            $.ajax({
                headers: {
                    "content-type": "application/x-www-form-urlencoded",
                    "Session": 'session5'
                },
                url: `${y}/generalPaginationQueryByTableName`,
                method: "POST",
                data,
                success: (res) => {
                    this.Total = res.Total;
                    this.tableData = res.Data;
                },
                complete: () => {
                    this.loading = false;
                }
            });
        },
        personalAdd() {
            window.location.href = './add.html'
        },
        handleEdit(row) {
            window.location.href = "./edit.html?nodeKey=" + row.Work_Log_SerialNumber;
        },
        Export() {
            this.loading1 = true;
            let Condition = "";
            try {
                Condition = " Start_Datetime BETWEEN '" + this.value[0] + " 00:00:00' AND '" + this.value[1] + " 23:59:59'";
            } catch (error) {
                Condition = " Start_Datetime BETWEEN '" + getYMDDate() + " 00:00:00' AND '" + getYMDDate() + " 23:59:59'";
            }
            $.ajax({
                headers: {
                    "content-type": "application/x-www-form-urlencoded",
                    "Session": 'session5'
                },
                url: `${y}/generalQueryByTableName`,
                method: "POST",
                data: {
                    TableName: "base_word_log",
                    Condition,
                },
                success: (res) => {
                    if (res.Status == 'success' && res.Data.length > 0) {
                        const wb = XLSX.utils.book_new();
                        const ws_data = [["序号", "任务编号", "功能", "内容", "开始时间", "结束时间"]];
                        let arr = res.Data.map((i, id) => [id + 1, i.Work_Number, i.Work_Name, i.Work_Main, i.Start_Datetime, i.End_Datetime]);
                        const ws = XLSX.utils.aoa_to_sheet([...ws_data, ...arr]);
                        ws['!cols'] = [];
                        ws_data[0].forEach(item => {
                            ws['!cols'].push({ wpx: 150 });
                        })
                        XLSX.utils.book_append_sheet(wb, ws, '工作日志');
                        XLSX.writeFile(wb, "工作日志" + (+new Date()) + ".xlsx");
                    } else {
                        this.$message({
                            type: 'warning',
                            message: '暂无可导出的数据'
                        });
                    }
                },
                complete: (XMLHttpRequest) => {
                    this.loading1 = false
                }
            });
        },
    },
};



const { createApp } = Vue;
const app = createApp(App);
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
const ElMessage = ElementPlus.ElMessage;
app.use(ElementPlus, { locale: zhCn });
app.mount("#app");
